#include<cstdio>//uncle-lu
#include<algorithm>
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}
int n, m;
int map[110][110];
int F[110][110];//表示我们的状态
int x_turn[4]={0, 0, 1, -1};
int y_turn[4]={1, -1 ,0, 0};

int DFS(int x, int y)
{
	if(F[x][y])return F[x][y];// 记忆化的部分

	for (int i = 0; i < 4; i++) 
	{
		int xx = x + x_turn[i], yy = y + y_turn[i];
		if( xx < 1 || xx > n || yy < 1 || yy > m )continue;
		if( map[xx][yy] >= map[x][y] )continue;
		F[x][y] = std::max(F[x][y], DFS(xx, yy) + 1);//状态转移方程
	}

	return F[x][y];
}

int main()
{
	read(n);read(m);
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= m; j++) 
			read(map[i][j]);

	int ans = 0;
	for (int i = 1; i <= n; i++) 
		for (int j = 1; j <= m; j++) 
			ans = std::max(ans, DFS(i,j));

	printf("%d", ans + 1);
	return 0;
}
